package com.zlz.m3u8download.util;

import com.zlz.m3u8download.bean.entity.CacheM3u8Entity;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author: zhulinzhong
 * @Date: 2024/11/29
 */
public class M3u8FileUtil {

    public static List<String> split(String content) {
        return Arrays.stream(content.split("\n")).map(String::trim).collect(Collectors.toList());
    }

    public static boolean isNotPath(String row) {
        return row.trim().startsWith("#");
    }

    public static boolean isAbsolute(String row) {
        return row.trim().startsWith("http");
    }

    public static boolean isM3u8(String row) {
        return row.trim().endsWith(".m3u8");
    }

    public static String videoVersion(String simple) {
        return "video_";
    }

    public static String genM3u8List(Map<String, String> videos, List<String> start) {
        StringBuilder builder = new StringBuilder();
        builder.append(String.join("\r\n", start)).append("\r\n");
        videos.forEach((key, value) -> {
            builder.append(key).append("\r\n").append(value).append("\r\n");
        });
        return builder.toString().trim();
    }
}
